<template>
  <div class="comModal">
    <el-dialog
      v-if="modalType == 'dialog'"
      :title="title"
      :visible.sync="show"
      :before-close="handleClose"
      :close-on-click-modal:="closeOnClickModal"
      :width="size"
    >
      <el-scrollbar :key="componentKey">
        <slot></slot>
      </el-scrollbar>
    </el-dialog>
    <el-drawer
      v-if="modalType == 'drawer'"
      :title="title"
      :visible.sync="show"
      :direction="direction"
      :wrapperClosable="false"
      :before-close="handleClose"
      :append-to-body="true"
      :size="size"
    >
      <el-scrollbar :key="componentKey">
        <slot></slot>
      </el-scrollbar>
    </el-drawer>
  </div>
</template>
<script>
export default {
  name: "com-modal",
  props: {
    visible: {
      type: Boolean,
      default: () => {
        return false;
      }
    },
    title: {
      type: String,
      default: () => {
        return "";
      }
    },
    modalType: {
      type: String,
      default: () => {
        return "drawer";
      }
    },
    size: {
      type: String,
      default: () => {
        return "70%";
      }
    },
    direction: {
      type: String,
      default: () => {
        return "rtl";
      }
    },
    operation: {
      type: String,
      default: () => {
        return "";
      }
    }
  },
  data() {
    return {
      componentKey: 0,
      type: "drawer",
      closeOnClickModal: true
    };
  },
  computed: {
    show() {
      return this.visible;
    }
  },
  watch: {
    show(neuValue) {
      if (neuValue) {
        ++this.componentKey;
      }
    }
  },
  mounted() {},
  methods: {
    handleClose() {
      this.$emit("close-modal");
    }
  }
};
</script>
<style scoped lang="scss">
.el-scrollbar {
  height: calc(100% - 10px);
}

::v-deep .el-scrollbar__wrap {
  overflow-x: hidden;
  height: calc(100%);
}

::v-deep .el-scrollbar__view {
  overflow-x: hidden;
  height: calc(100%);
}

::v-deep .el-drawer__header {
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  color: #72767b;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  margin-bottom: 10px;
  padding: 24px;
  padding-bottom: 0;
}

::v-deep .el-drawer__body {
  -webkit-box-flex: 1;
  -ms-flex: 1;
  flex: 1;
  overflow-y: auto;
}

//dialog
::v-deep .el-dialog {
  position: relative;
  margin: 50px auto 0 auto !important;
  padding: 15px 0;
  background: #fff;
  border-radius: 2px;
  -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  height: calc(100% - 100px) !important;
  width: 60%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

::v-deep .el-dialog__body {
  flex: 1;
  position: relative;
  padding: 10px 10px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
  height: calc(100%-50px) !important;
  overflow: auto;
}

@media screen and (max-width: 1920px) {
  ::v-deep .el-dialog {
    position: relative;
    margin: 40px auto 0 auto !important;
    padding: 15px 0;
    background: #fff;
    border-radius: 2px;
    -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    height: calc(100% - 100px) !important;
    width: 70%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  ::v-deep .el-dialog__body {
    flex: 1;
    position: relative;
    padding: 10px 10px;
    color: #606266;
    font-size: 14px;
    word-break: break-all;
    height: calc(100%-50px) !important;
    overflow: auto;
  }
}
@media screen and (max-width: 1368px) {
  ::v-deep .el-dialog {
    position: relative;
    margin: 30px auto 0 auto !important;
    padding: 15px 5px 0 5px;
    background: #fff;
    border-radius: 2px;
    -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    height: calc(100% - 70px) !important;
    width: 70%;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  ::v-deep .el-dialog__wrapper .el-dialog .el-dialog__header,
  .el-dialog__wrapper .el-drawer__container .el-drawer__header,
  .el-drawer__wrapper .el-drawer__container .el-drawer__header {
    border-bottom: 1px solid #b6b7b9 !important;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    height: 20px;
    padding: 16px !important;
    display: flex;
    flex-direction: row;
    align-items: center;
  }

  ::v-deep .el-dialog__wrapper .el-dialog .el-dialog__header .el-dialog__title,
  .el-dialog__wrapper .el-drawer__container .el-drawer__header span,
  .el-drawer__wrapper .el-drawer__container .el-drawer__header span {
    color: #303133;
    font-size: 16px !important;
    font-weight: 600 !important;
    font-family: "Microsoft YaHei", "\5FAE\8F6F\96C5\9ED1", Arial, sans-serif,
      "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB";
    display: inline-block;
    height: 16px;
    /* line-height: 6px; */
  }
  ::v-deep .el-dialog__body {
    flex: 1;
    position: relative;
    color: #606266;
    padding: 0;
    font-size: 14px;
    word-break: break-all;
    height: calc(100%-50px) !important;
    overflow: auto;
  }
}
</style>
